package NWPackage;

import java.util.List;

public class PairPreferdCandidateCell extends Cell implements Comparable<PairPreferdCandidateCell>{

	private String C1;
	private String C2;
	private String prefered_C;
	
	public PairPreferdCandidateCell() {
		super();
	}
	public PairPreferdCandidateCell(String agentName) {
		super(agentName);
	}
	public PairPreferdCandidateCell(String agentName,int index, String c1, String c2) {
		super(agentName,index);
		this.setCandidates(c1,c2);
	}
	public PairPreferdCandidateCell(String agentName,String c1, String c2, String prefered_C) {
		super(agentName);
		this.setCandidates(c1,c2);
		this.setPrefered_C(prefered_C);
	}
	public void setCandidates(String c1,String c2) {
		C1 = c1;
		C2 = c2;
	}
	public String[] getCandidates() {
		String[] candidates = new String[2];
		candidates[0] = C1;
		candidates[1] = C2;
		return candidates;
	}
	
	public void setPrefered_C(String prefered_C) {
		this.prefered_C = prefered_C;
		super.setAlgPreffered(prefered_C);
	}
	
	public String getPrefered_C() {
		return prefered_C;
	}
	
	/*returns the cands, the preferred cand is in place[1]*/
	public String[] getCandidatesByPrefferedOrder() {
		String temp;
		String[] candidates = this.getCandidates();
		if (this.getPrefered_C().equals(candidates[0]))//edit
		{
			temp = candidates[1];
			candidates[1] = candidates[0];
			candidates[0] = temp;
		}
		return candidates;
	}
	
	public boolean equals(PairPreferdCandidateCell otherCell)
	{
		if (otherCell.getAgentName() == this.getAgentName())
		{
			if ((otherCell.C1 == this.C1 && otherCell.C2 == this.C2) || (otherCell.C2 == this.C1 && otherCell.C1 == this.C2)){	
				return true;
			}
		}
		return false;
	}
	
	/***
	 * 
	 * @param possibleWinners List
	 * @return True if at least one of the candidates appear in the Possible List
	 */
	public boolean isExistIn(List<String> possibleWinners) {
		if (possibleWinners.contains(C1) || possibleWinners.contains(C2))
			return true;
		return false;
	}
	public boolean equals(Object obj){ 
		boolean ans = false;
		ans = this.equals((PairPreferdCandidateCell)obj);
		return ans;
	}
	@Override
	public int compareTo(PairPreferdCandidateCell o) {
		if (this.equals(o))
			return 0;
		return -1;
	}
	public boolean isContain(String winner) {
		if (winner == this.C1 || winner == this.C2)
			return true;
		return false;
	}
	
	public boolean isContainPreferred(String winner) {
		if (winner == this.prefered_C)
			return true;
		return false;
	}
	
	 
	/*
	private String setRealVote() throws NullPointerException{
		String agentName = super.getAgentName();
		RealVoteCell realVote = null;
		for(int i=0; i<)
		
		for (RealVoteCell vote : (RealVoteCell[])this.cells) {
			String thisAgent = vote.getAgentName();
			//int thisAgent_int = Integer.parseInt(thisAgent);
			double thisAgent_int = Double.parseDouble(thisAgent);
			//int agentName_int = Integer.parseInt(agentName);
			double agentName_int = Double.parseDouble(agentName);
			//if (thisAgent.equals(agentName))   //Lihi changed this from strings to ints, 6.2.13
			if (thisAgent_int == agentName_int)
				realVote = vote;
		}
		
		int index_0 = realVote.getIndexOf(this.C1);
		int index_1 = realVote.getIndexOf(this.C2);
		
		if (index_0 > index_1){
			setPrefered_C(this.C1);
			return this.C1;
		}
		else{
			setPrefered_C(this.C2);
			return this.C2;
		}
		
	} */
	
	

}
